package br.com.fiap.vendas.business.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Remote;
import javax.ejb.Stateless;

import br.com.fiap.vendas.business.dao.interfaces.ClienteDAO;
import br.com.fiap.vendas.business.entity.ClienteEntity;
import br.com.fiap.vendas.business.service.interfaces.ClienteService;
import br.com.fiap.vendas.business.vo.ClienteVO;

@Remote(ClienteService.class)
@LocalBean
@Stateless
public class ClienteServiceImpl implements ClienteService {

    @EJB
    ClienteDAO clienteDAO;

    @Override
    public void inserirCliente(ClienteVO clienteVO) {
        ClienteEntity clienteEntity = ClienteEntity.build(clienteVO);
        clienteDAO.inserirCliente(clienteEntity);

    }

    @Override
    public List<ClienteVO> listarClientes() {

        List<ClienteEntity> clientesEntitys = clienteDAO.listarClientes();
        List<ClienteVO> clienteVOs = new ArrayList<ClienteVO>();
        for (ClienteEntity clienteEntity : clientesEntitys) {
            clienteVOs.add(clienteEntity.buildVO());
        }
        return clienteVOs;
    }

    @Override
    public List<ClienteVO> buscarClientesComPedidos() {
        List<ClienteEntity> clientesEntitys = clienteDAO.buscarClientesComPedidos();
        List<ClienteVO> clienteVOs = new ArrayList<ClienteVO>();
        for (ClienteEntity clienteEntity : clientesEntitys) {
            clienteVOs.add(clienteEntity.buildVO());
        }
        return clienteVOs;
    }

}
